/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package program.beans;

import java.math.BigDecimal;
import java.math.MathContext;
import java.sql.Timestamp;
import java.text.NumberFormat;

/**
 * Beans class to represent the amount of a bill with id, brutto and percentage
 * as attributes
 *
 * Responsible: Patrick
 */
public class BillAmount {

    private Timestamp bid;
    private BigDecimal brutto;
    private BigDecimal percentage;

    public BillAmount(Timestamp bid, BigDecimal brutto, BigDecimal percentage) {
        this.bid = bid;
        this.brutto = brutto;
        this.percentage = percentage;
    }

    public BillAmount(BigDecimal brutto, BigDecimal percentage) {
        this.brutto = brutto;
        this.percentage = percentage;
    }

    public BigDecimal getBrutto() {
        return brutto;
    }

    public void setBrutto(BigDecimal brutto) {
        this.brutto = brutto;
    }

    public Timestamp getBid() {
        return bid;
    }

    public void setBid(Timestamp bid) {
        this.bid = bid;
    }

    public BigDecimal getPercentage() {
        return percentage;
    }

    public void setPercentage(BigDecimal percentage) {
        this.percentage = percentage;
    }

    /**
     * Calculates brutto-amount to netto-amount and returns it
     * 
     * @return netto-amount 
     */
    public BigDecimal getNetto() {
        BigDecimal perc = percentage.divide(new BigDecimal(100));
        perc = perc.add(new BigDecimal(1));

        if (perc.doubleValue() == 0) {
            return BigDecimal.ZERO;
        }
        
        return brutto.divide(perc, MathContext.DECIMAL32);
    }

    public String getBruttoFormated() {
        return NumberFormat.getCurrencyInstance().format(brutto.doubleValue());
    }

    public String getNettoFormated() {
        return NumberFormat.getCurrencyInstance().format(this.getNetto().doubleValue());
    }

    @Override
    public String toString() {
        return "BillAmount{" + "bid=" + bid + ", brutto=" + brutto + ", percentage=" + percentage + '}';
    }
}
